Real numbers in GameMaker Studio 2 are considered double-precision floating-point numbers - that is to say that they have a decimal point in them with no fixed number of digits either before or after the point - or integers - that is to say they are whole numbers with no decimal point value. 2, for example, is an integer but 2.01 is a floating point real.
This distinction between integers and floats is very important when
dealing with cross platform development as the precision of
calculations made on a Windows PC is not the same as the
precision of those same calculations when made on a mobile device.
This means that you should pay particular attention when making
comparisons, for example:
if image_index == 1 {do something...}
In the example above, if we have been setting the
image_speed to 0.25 - for example - then after four steps
you may assume that the image_index value would be 1, but
it may be a value like 1.0000002 due to the way floating
point maths works and so the evaluation will not be true.
These types of errors can be quite hard to debug and so it is
always good to be aware of them and to plan ahead and use other
means of checking values or to use the appropriate flooring or
rounding functions (listed below) to convert the number to check
into an integer (for more information on floating point maths and
why this is an issue, please see here). For
example the above code could be written as:
if floor(image_index) == 1 {do something...}
It is also worth noting that when using the YoYo Compiler
targets, all expressions and functions are evaluated from left
to right, while on all other target platforms they are
evaluated from right to left, meaning that this - for
example - will give different results depending on the
platform:
val = max(num, ++num, num++);
You can also use a special function available in GameMaker
Studio 2 to set the epsilon value for floating point
maths. When a real number is rounded to the nearest floating point
number, the epsilon (also know as "machine epsilon") forms an upper
bound on the relative error, and you can get and set the epsilon
value using the following functions:
We can split the functions that GameMaker Studio 2 has
for dealing with real numbers into the following
categories:
These functions all deal with using random numbers and values:
NOTE: When using the random functions, GameMaker Studio 2 maintains the same random seed every time you start the game. This makes debugging much easier as you are guaranteed that the random functions will always return the same value, however should you not wish this to happen, you must first set a new random seed at the very start of the game, either using randomise or random_set_seed.
These are all trigonometric functions:
- arccos
- arcsin
- arctan
- arctan2
- sin
- tan
- cos
- darccos
- darcsin
- darctan
- darctan2
- dsin
- dtan
- dcos
- degtorad
- radtodeg
- lengthdir_x
- lengthdir_y
Note that GameMaker Studio 2 also has a number of vector functions that can be very handy when working with the trigonometric functions. See the following page for more information:
These are all functions that round or select values: